package com.lbh.graphics;

import com.alibaba.fastjson.annotation.JSONField;
import com.jogamp.opengl.GL2;

import java.util.List;

import static com.lbh.graphics.GLUtils.getLines;

/***
 * project:JRuntime
 * package:com.lbh.graphics
 *
 * @author user:lenovo QQ:1601078366
 * @date 2021/10/21 23:03
 * @version V1.0
 */
public class GLShader {

    @JSONField(serialize = false, deserialize = false)
    int shader;
    @JSONField(name = "stage")
    public int stage;
    @JSONField(name = "code")
    public List<String> code;

    public GLShader(GL2 gl, int stage, String source){
        this.stage = stage;
        shader = gl.glCreateShader(stage);
        code = getLines(source);
        GLUtils.compile(gl, code, shader);
    }

    public int get(){
        return shader;
    }

    public void delete(GL2 gl){
        gl.glDeleteShader(shader);
    }
}
